package com.ivan.toolkit.common;

import java.util.List;

import com.google.common.collect.Lists;

public abstract class RunningInfo {
	
	private static List<RunningInfo> contents = Lists.newArrayList();
	
	public static String build() {
		ContentBuilder builder = new ContentBuilder();
		for(RunningInfo ri : contents) 
			ri.buildRunningInfo(builder);
		return builder.getContent();
	}
	
	public RunningInfo() {
		contents.add(this);
	}
	
	abstract protected void buildRunningInfo(ContentBuilder builder);
	
	public static class ContentBuilder {
		
		private StringBuilder builder;

		private ContentBuilder() {
			super();
			this.builder = new StringBuilder();
		}
		
		public void buildSectionName(String name) {
			builder.append("[" + name + "]\r\n");
		}
		
		public void buildKeyValue(String key, Object value) {
			builder.append(key).append("= ").append(value).append("\r\n");
		}
		
		public String getContent() {
			return builder.toString();
		}
		
	}
	
}
